var selectedRow;
$(function () {
    initScanQrCodePage('minApp', 'check', doPass, openDoUnPassPage, refreshQrCode);
});

// dataTable
$('#dataTable').on("click-row.bs.table", function (e, row, $element) {
    // checkBox 的勾选
    var index = $element[0].rowIndex - 1;
    $('#dataTable').bootstrapTable('check', index);
    $('#dataTable .success').removeClass('success');//去除之前选中的行的，选中样式
    $element.addClass('success');//添加当前选中的 success样式用于区别
    selectedRow = row;
    doRefreshLog();
});

function checkPass() {
    swalToastr('审核通过',  '确定通过审核吗？', 'warning', doPass, '审核通过');
}

/*审核通过*/
function doPass() {
    var postData = {
        batchId : $("#batchId").val()
    };
    $.ajax({
        type: 'post',
        url: basePath + 'checkApp/checkDocTeam/doPass?hasOrg='+ defLogInfo.hasOrg + '&hasTeam='+ defLogInfo.hasTeam + '&hasApp='+ defLogInfo.hasApp +'&t=' + new Date().getTime(),
        dataType: 'json',
        contentType: "application/json",
        data: JSON.stringify(postData),
        success : function (data) {
            if (!data) {
                toastr.error('合并失败');
                return;
            }
            if (!data.isSuccess) {
                toastr.error(data.errorDesc);
                return;
            }
            if(data.isSuccess){
                doBack();
            }
        },
    });
}

function openDoUnPassPage() {
    $('#unPassModal').modal('show');
}

/*审核不通过*/
function doUnPass() {
    var reason = $('#reason').val();
    if (!reason) {
        toastr.error('原因不能为空');
        return;
    }
    var postData = {
        batchId : $("#batchId").val(),
        reason : reason
    };
    $.ajax({
        type: 'post',
        url: basePath + 'checkApp/checkDocTeam/doUnPass?hasOrg='+ defLogInfo.hasOrg + '&hasTeam='+ defLogInfo.hasTeam + '&hasApp='+ defLogInfo.hasApp +'&t=' + new Date().getTime(),
        dataType: 'json',
        contentType: "application/json",
        data: JSON.stringify(postData),
        success : function (data) {
            if (!data) {
                toastr.error('不通过操作失败');
                return;
            }
            if (!data.isSuccess) {
                toastr.error(data.errorDesc);
                return;
            }
            if(data.isSuccess){
                doBack();
            }
        },
    });
}

/*关闭合并层*/
function closeMergeModal() {
    $("#mergeModal").modal('hide');
}

function closeUnPassModal() {
    $('#reason').val('');
    $("#unPassModal").modal('hide');
}

$('#unPassModal').on('hidden.bs.modal', function () {
    // 执行一些动作...
    $('#reason').val('');
});

/*返回*/
function doBack() {
    var str = '&docName=' + searchInfo.docName + '&teamName=' + searchInfo.teamName + '&timeInterval=' + searchInfo.timeInterval + '&timeInterval1=' + searchInfo.timeInterval1
        + '&checkType=' + searchInfo.checkType + '&orgCode=' + searchInfo.orgCode + '&result=' + searchInfo.result + '&status='+ searchInfo.status +
        '&hasOrg='+ defLogInfo.hasOrg + '&hasTeam='+ defLogInfo.hasTeam + '&hasApp='+ defLogInfo.hasApp +
        searchInfo.orgName + '&pageNo=' + searchInfo.pageNo + '&pageSize=' + searchInfo.pageSize;
    window.location.href = basePath + 'checkApp/checkDocTeam/checkDocTeamPage?t=' + new Date().getTime() + str;
}


//new
function openViewPage() {
    var url = basePath + 'checkApp/checkDocTeam/getQrCode';
    var data = {
        teamCode : $("#teamCode").val(),
        id : $("#teamId").val(),
    };
    doShowQrCode(url, data, 'minApp');
}

function refreshQrCode() {
    var url = basePath + 'checkApp/checkDocTeam/getQrCode';
    var data = {
        teamCode : $("#teamCode").val(),
        id : $("#teamId").val(),
    };
    doRefreshQrCode(url, data, 'minApp');
}